package com.golang.api.util;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Slf4j
public class ResponseJsonUtil {

  public static void responseJson (HttpServletResponse response, Object obj) {
    String json = JsonUtils.toJson(obj);
    try {
      response.setContentType("application/json; charset=UTF-8");
      PrintWriter out = response.getWriter();
      out.print(json);
      out.flush();
      out.close();
    } catch (IOException e) {
      log.error("response write error, data: {}", json, e);
    }
  }

}
